home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / propdlg / shapesvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  4.7 KB  |  186 lines

  1. // shapesvw.cpp : implementation of the CShapesView class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1999 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "propdlg.h"
  15.  
  16. #include "shapeobj.h"
  17. #include "colorpge.h"
  18. #include "stylepge.h"
  19. #include "propsht.h"
  20. #include "propsht2.h"
  21. #include "shapedoc.h"
  22. #include "shapesvw.h"
  23.  
  24. #include "mainfrm.h"
  25.  
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char BASED_CODE THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CShapesView
  33.  
  34. IMPLEMENT_DYNCREATE(CShapesView, CView)
  35.  
  36. BEGIN_MESSAGE_MAP(CShapesView, CView)
  37.     ON_MESSAGE(WM_USER_CHANGE_OBJECT_PROPERTIES, OnChangeObjectProps)
  38.     //{{AFX_MSG_MAP(CShapesView)
  39.     ON_WM_LBUTTONDOWN()
  40.     ON_COMMAND(ID_SIMPLE_PROPERTY_SHEET, OnSimplePropertySheet)
  41.     //}}AFX_MSG_MAP
  42.     // Standard printing commands
  43. END_MESSAGE_MAP()
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CShapesView construction/destruction
  47.  
  48. CShapesView::CShapesView()
  49. {
  50.     m_pShapeSelected = NULL;
  51.     m_pModalShapePropSheet = NULL;
  52. }
  53.  
  54. CShapesView::~CShapesView()
  55. {
  56. }
  57.  
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CShapesView drawing
  61.  
  62. void CShapesView::OnDraw(CDC* pDC)
  63. {
  64.     CShapesDoc* pDoc = GetDocument();
  65.     ASSERT_VALID(pDoc);
  66.  
  67.     CRect rectDirty, rectIntersect;
  68.     pDC->GetClipBox(&rectDirty);
  69.     if (rectDirty.IsRectNull())
  70.         GetClientRect(&rectDirty);
  71.  
  72.  
  73.     CShape* pShape;
  74.     POSITION pos = pDoc->m_shapeList.GetTailPosition();
  75.     // Draw all of the shapes, except the currently selected shape, from
  76.     // back to front.
  77.     while (pos != NULL)
  78.     {
  79.         pShape = pDoc->m_shapeList.GetPrev(pos);
  80.         if (rectIntersect.IntersectRect(&pShape->m_rect, &rectDirty) != 0
  81.             && pShape != m_pShapeSelected)
  82.             pShape->Draw(pDC, FALSE);
  83.     }
  84.     // Draw the selected shape on top
  85.     if (m_pShapeSelected != NULL)
  86.         m_pShapeSelected->Draw(pDC, TRUE);
  87. }
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CShapesView diagnostics
  91.  
  92. #ifdef _DEBUG
  93. void CShapesView::AssertValid() const
  94. {
  95.     CView::AssertValid();
  96. }
  97.  
  98. void CShapesView::Dump(CDumpContext& dc) const
  99. {
  100.     CView::Dump(dc);
  101. }
  102.  
  103. CShapesDoc* CShapesView::GetDocument() // non-debug version is inline
  104. {
  105.     ASSERT_KINDOF(CShapesDoc, m_pDocument);
  106.     return (CShapesDoc*)m_pDocument;
  107. }
  108. #endif //_DEBUG
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CShapesView message handlers
  112.  
  113. void CShapesView::OnLButtonDown(UINT /*nFlags*/, CPoint point)
  114. {
  115.     CShapesDoc* pDoc = GetDocument();
  116.  
  117.     CClientDC dc(this);
  118.  
  119.     CShape* pShapeHit;
  120.     pShapeHit = pDoc->HitTest(point);
  121.     if (pShapeHit != NULL)
  122.     {   // Select the object that was clicked.
  123.  
  124.         CRect rectInvalid;
  125.         // Invalidate the previously selected object, so it will
  126.         // be redrawn as unselected.
  127.         if (m_pShapeSelected != NULL)
  128.             InvalidateRect(&m_pShapeSelected->m_rect);
  129.         m_pShapeSelected = pShapeHit;
  130.  
  131.         // Invalidate the newly selected object, so it will be
  132.         // redrawn as selected.
  133.         InvalidateRect(&m_pShapeSelected->m_rect);
  134.     }
  135.     else
  136.     {   // Add a new shape
  137.  
  138.         CShape* pShapeNew = new CShape(
  139.             black,
  140.             rectangle,
  141.             CRect(point.x-50, point.y-50, point.x + 50, point.y + 50));
  142.         pDoc->AddShape(pShapeNew);
  143.         m_pShapeSelected = pShapeNew;
  144.     }
  145. }
  146.  
  147. void CShapesView::OnSimplePropertySheet()
  148. {
  149.     if (m_pShapeSelected == NULL)
  150.         return;
  151.  
  152.     CPropertySheet dlgPropertySheet(AFX_IDS_APP_TITLE);
  153.     CStylePage stylePage;
  154.     CColorPage colorPage;
  155.  
  156.     stylePage.m_nShapeStyle = m_pShapeSelected->m_shapestyle;
  157.     colorPage.m_nColor = m_pShapeSelected->m_shapecolor;
  158.  
  159.     dlgPropertySheet.AddPage(&stylePage);
  160.     dlgPropertySheet.AddPage(&colorPage);
  161.  
  162.     if (dlgPropertySheet.DoModal() == IDOK)
  163.     {
  164.         m_pShapeSelected->m_shapecolor = colorPage.m_nColor;
  165.         m_pShapeSelected->m_shapestyle
  166.             = (SHAPE_STYLE)stylePage.m_nShapeStyle;
  167.         GetDocument()->SetModifiedFlag();
  168.         GetDocument()->UpdateAllViews(NULL);
  169.     }
  170. }
  171.  
  172. LRESULT CShapesView::OnChangeObjectProps(WPARAM, LPARAM)
  173. {
  174.     // The user-defined WM_USER_CHANGE_OBJECT_PROPS message is sent
  175.     // by the modal CModalShapePropSheet when the user chooses Apply Now,
  176.     // or by the modeless CModelessShapePropSheet when the user
  177.     // changes any setting in a property page.
  178.  
  179.     if (m_pShapeSelected == NULL)
  180.         return 0;
  181.  
  182.     GetDocument()->SetModifiedFlag();
  183.     GetDocument()->UpdateAllViews(NULL);
  184.     return 0;
  185. }
  186.